//
//  PersonDataModifyView.m
//  QcMedical1
//
//  Created by ios001 on 2016/12/25.
//  Copyright © 2016年 jiawen Du. All rights reserved.
//

#import "PersonDataModifyView.h"

@interface PersonDataModifyView ()<UIPickerViewDelegate,UIPickerViewDataSource>

@property (weak, nonatomic) IBOutlet UIPickerView *personDataPickerView;

@end

@implementation PersonDataModifyView

+ (instancetype)personDataModifyView{
    return [[[UINib nibWithNibName:@"PersonDataModify" bundle:nil] instantiateWithOwner:nil options:nil] lastObject];
}

-(void)setDataArray:(NSArray *)dataArray{
    _dataArray = dataArray;
    [self.personDataPickerView selectRow:_dataArray.count / 2 inComponent:0 animated:NO];
}


- (void)awakeFromNib{
    [super awakeFromNib];
    
    [self layoutIfNeeded];
    
    self.personDataPickerView.delegate = self;
    self.personDataPickerView.dataSource = self;
    
    UIImage *image = [UIImage imageNamed:@"NewFeature1"];
    
    
    [self.personDataPickerView.subviews[0] setBackgroundColor:[UIColor colorWithPatternImage:image]];

 
}
- (IBAction)clickSure:(UIButton *)sender {
    
    NSInteger selectRow = [self.personDataPickerView selectedRowInComponent:0];
    NSString *rowStr = [_dataArray[selectRow] description];
    
    if ([self.delegate respondsToSelector:@selector(modifyViewCommitWithString:)]) {
        [self.delegate modifyViewCommitWithString:rowStr];
    }
    
    [self clickCancel:nil];
    
}
- (IBAction)clickCancel:(UIButton *)sender {
    
    [UIView animateWithDuration:0.5 delay:0 usingSpringWithDamping:0.8 initialSpringVelocity:1 options:0 animations:^{
        
        if ([self.delegate respondsToSelector:@selector(modifyViewDidmiss)]) {
            [self.delegate modifyViewDidmiss];
        }
        
        self.transform = CGAffineTransformMakeScale(0.01, 0.01);
        
    } completion:^(BOOL finished) {
        
        [self  removeFromSuperview];
    }];
}

#pragma mark - dataSource
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    return _dataArray.count;
}

#pragma mark - delegate
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    return [_dataArray[row] description];
}

@end
